﻿using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Web;
using System.Web.Services;
using System.Web.Services.Protocols;
//new
using System.IO;
using DataInterfaceDLL;
using System.Configuration;
using System.Xml;

namespace AimtsIPoliceWebService
{
    /// <summary>
    /// aitmskdws 的摘要说明
    /// </summary>
    [WebService(Namespace = "http://www.jarits.com/")]
    [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
    [ToolboxItem(false)]
    public class aitmskdws : System.Web.Services.WebService
    {
        private static string gListernIP = ConfigurationManager.AppSettings.Get("ListernIP");
        private static int gListernPort = int.Parse(ConfigurationManager.AppSettings.Get("ListernPort"));
        private static string gLocalIP = ConfigurationManager.AppSettings.Get("LocalIP");     //本机搭建http服务的ip
        private static string gKKIISName = ConfigurationManager.AppSettings.Get("KKIISName");  //卡口虚拟目录别名
        private static string gKKIISPath = ConfigurationManager.AppSettings.Get("KKIISPath"); //卡口虚拟目录
        private static string gDJIISName = ConfigurationManager.AppSettings.Get("DJIISName");  //电警虚拟目录别名
        private static string gDJIISPath = ConfigurationManager.AppSettings.Get("DJIISPath"); //电警虚拟目录
        private static string gIndexMode = ConfigurationManager.AppSettings.Get("IndexMode");//索引模式
        private static string gKKDB = ConfigurationManager.AppSettings.Get("KKDB");//索引模式
        private static string gDJDB = ConfigurationManager.AppSettings.Get("DJDB");//索引模式
        private static string gVersion = ConfigurationManager.AppSettings.Get("Version");//索引模式
        private static UploadClient m_client = new UploadClient(gListernIP, gListernPort);

        private void InitializeComponent()
        {

        }

        /// <summary>
        /// Aimts卡电数据转发中间件的WebService接口,实现杰瑞图片索引(V1.03)
        /// </summary>
        /// <param name="SnapCount">must,一组图片数量1-6</param>
        /// <param name="picJionMode">must,图片合成模式0-不合成,1-合成</param>
        /// <param name="recordType">must,记录类型,0-卡口,1-低速,2-超速,3-逆行,4-违反交通灯指示,5-压车道线,6-不按导向,7-路口滞留,8-机占非,9-违法变道,10-机动车违反规定使用专用车道,11-黄牌车禁限,12-监控抓拍</param>
        /// <param name="Company">must,数据提供厂家:我方-JARI,其他厂家按约定</param>
        /// <param name="captureDevice">not must,采集设备,0-HK200万摄像机,1-HK300万摄像机,2-HK500万摄像机,3-DH200万摄像机,4-DH300万摄像机,5-DH500万摄像机,6-HK130万球机,7-HK200万球机,8-DH130万球机,9DH200万球机</param>
        /// <param name="deviceID">must,设备编号,采集设备的唯一标识编号</param>
        /// <param name="captureUser">not must,采集人员,当记录类型为“12监控抓拍时”指定采集人员用户名,闯红灯等自动抓拍系统为"Auto", 没有设为空。</param>
        /// <param name="WFXWDM">not must,违法行为代码,本记录对应的违法行为代码,没有设为空。</param>
        /// <param name="GBDM">must,路口外部编号,路口的国标代码,城区9位,郊区12位：5位道路代码+4位公里数+3位米数</param>
        /// <param name="BMBH">must,部门编号,交警部门行政编号,如：张家界430800000000</param>
        /// <param name="roadid">must,路口内部编号</param>
        /// <param name="roadname">must,路口名称,不能含有_字符</param>
        /// <param name="directionID">must,方向1-由东向西 2-由南向北 3-由西向东 4-由北向南</param>
        /// <param name="CD">must,车道,由路口渠化由中间线到路边依次为1,2,3,4,5-9</param>
        /// <param name="yyyy">must,年,4位</param>
        /// <param name="MM">must,月,2位</param>
        /// <param name="dd">must,日,2位</param>
        /// <param name="HH">must,时,2位</param>
        /// <param name="mm">must,分,2位</param>
        /// <param name="ss">must,秒,2位</param>
        /// <param name="fff">must,毫秒,3位</param>
        /// <param name="RedLightBeginTime">not must,红灯开始时间,格式为：yyyy-MM-dd hh:mm:ss,由检测器给出时间</param>
        /// <param name="RedLightDuration">not must,红灯持续时间,单位秒,由检测器给出时间</param>
        /// <param name="plateType">not must,车牌类型0---标准民用与军车车牌1---02 式民用车牌2---军车牌3---警车车牌4---民用车双行尾牌</param>
        /// <param name="plateColor">not must,车牌颜色,蓝 黄 白 黑,没有为空字符串</param>
        /// <param name="HPHM">not must,车牌号,车牌的汉字和大写字母以及数字部分,没有为空字符串</param>
        /// <param name="bodyColor">not must,车身颜色,0-其他色 1-白色 2-银色 3-灰色 4-黑色 5-红色 6-深蓝7-蓝色 8-黄色 9-绿色 10-棕色 11-粉色 12-紫色,没有为空字符串</param>
        /// <param name="speedLimit">not must,限速,无限速为空字符串</param>
        /// <param name="speed">not must,车速,无车速为空字符串</param>
        /// <param name="PIC1">must,图片1,withpic=true时,为不含路径图片名,withpic=false时,为图片网络访问名</param>
        /// <param name="PIC2">not must,图片2,withpic=true时,为不含路径图片名,withpic=false时,为图片网络访问名</param>
        /// <param name="PIC3">not must,图片3,withpic=true时,为不含路径图片名,withpic=false时,为图片网络访问名</param>
        /// <param name="PIC4">not must,图片4,withpic=true时,为不含路径图片名,withpic=false时,为图片网络访问名</param>
        /// <param name="PICZoom">not must,缩略图或压缩图,withpic=true时,为不含路径图片名,withpic=false时,为图片网络访问名</param>
        /// <param name="PICPlate">not must,车牌图,withpic=true时,为不含路径图片名,withpic=false时,为图片网络访问名</param>
        /// <param name="withpic">是否上传图片,true-上传,false-不上传</param>
        /// <param name="PIC1Bytes">withpic=true时must,图片1数据byte[]</param>
        /// <param name="PIC2Bytes">not must,图片2数据byte[]</param>
        /// <param name="PIC3Bytes">not must,图片3数据byte[]</param>
        /// <param name="PIC4Bytes">not must,图片4数据byte[]</param>
        /// <param name="PICZoomBytes">not must,缩略图数据byte[]</param>
        /// <param name="PICPlateBytes">not must,车牌图片数据byte[]</param>
        /// <param name="error">错误描述</param>
        /// <returns>上传结果,true-成功false-失败</returns>
        [WebMethod]
        public bool Upload(string SnapCount, string picJionMode, string recordType, string Company,
                           string captureDevice, string deviceID, string captureUser, string WFXWDM,
                           string GBDM, string BMBH, string roadid, string roadname,
                           string directionID, string CD, string yyyy, string MM,
                           string dd, string HH, string mm, string ss,
                           string fff, string RedLightBeginTime,
                           string RedLightDuration, string plateType, string plateColor, string HPHM,
                           string bodyColor, string speedLimit, string speed, string PIC1,
                           string PIC2, string PIC3, string PIC4, string PICZoom,
                           string PICPlate, bool withpic, byte[] PIC1Bytes, byte[] PIC2Bytes,
                           byte[] PIC3Bytes, byte[] PIC4Bytes, byte[] PICZoomBytes, byte[] PICPlateBytes, out string error)
        {
            bool ans = false;
            error = "";
            try
            {
                try
                {
                    #region 参数校验
                    #region SnapCount must 一组图片数量（不包括缩略图和车牌小图）,必须项,1,2,3
                    if (String.IsNullOrEmpty(SnapCount) == true)
                    {
                        error = "SnapCount不能为空";
                        return false;
                    }
                    else
                    {
                        try
                        {
                            if (SnapCount.Length != 1)
                            {
                                error = "SnapCount长度错误";
                                return false;
                            }
                            if (SnapCount.Contains("_"))
                            {
                                error = "SnapCount包含_字符";
                                return false;
                            }
                            int i = int.Parse(SnapCount);
                            if ((i < 1) || (i > 6))
                            {
                                error = "SnapCount值超出范围";
                                return false;
                            }

                        }
                        catch (FormatException)
                        {
                            error = "SnapCount格式错误";
                            return false;
                        }
                    }
                    #endregion

                    #region picJionMode must 图片合成模式,必选项,0-不合成,1-合成
                    if (String.IsNullOrEmpty(picJionMode) == true) { error = "picJionMode不能为空"; return false; }
                    else
                    {
                        if (picJionMode.Length != 1)
                        {
                            error = "picJionMode长度错误";
                            return false;
                        }
                        if (picJionMode.Contains("_"))
                        {
                            error = "picJionMode包含_字符";
                            return false;
                        }
                        if ((picJionMode != "0") && (picJionMode != "1"))
                        {
                            error = "picJionMode值超出范围";
                            return false;
                        }
                    }
                    #endregion

                    #region recordType must 记录类型,must,0-卡口,1-低速,2-超速,3-逆行,4-违反交通灯指示,5-压车道线,6-不按导向,7-路口滞留,8-机占非,9-违法变道,10-机动车违反规定使用专用车道,11-黄牌车禁限,12-监控抓拍
                    if (String.IsNullOrEmpty(recordType) == true) { error = "recordType不能为空"; return false; }
                    else
                    {
                        if (recordType.Length > 2)
                        {
                            error = "recordType长度错误";
                            return false;
                        }
                        if (recordType.Contains("_"))
                        {
                            error = "recordType包含_字符";
                            return false;
                        }
                        try
                        {
                            int i = int.Parse(recordType);
                            if ((i < 0) || (i > 12))
                            {
                                error = "recordType值超出范围";
                                return false;
                            }
                        }
                        catch (FormatException)
                        {
                            error = "recordType格式错误";
                            return false;
                        }
                    }
                    #endregion

                    #region Company must 数据提供厂家,must,我方（JARI）,其他厂家按约定。
                    if (String.IsNullOrEmpty(Company) == true) { error = "Company不能为空"; return false; }
                    else
                    {
                        if (Company.Contains("_"))
                        {
                            error = "Company包含_字符";
                            return false;
                        }
                    }
                    #endregion

                    #region captureDevice not must采集设备,not must,0-HK200万摄像机,1-HK300万摄像机,2-HK500万摄像机,3-DH200万摄像机,4-DH300万摄像机,5-DH500万摄像机,6-HK130万球机,7-HK200万球机,8-DH130万球机,9DH200万球机
                    if (captureDevice == null) { error = "captureDevice不能为null"; return false; }
                    else
                    {
                        if (captureDevice != "")
                        {
                            if (captureDevice.Length > 1)
                            {
                                error = "captureDevice长度错误";
                                return false;
                            }
                            if (captureDevice.Contains("_"))
                            {
                                error = "captureDevice包含_字符";
                                return false;
                            }
                            try
                            {
                                int i = int.Parse(captureDevice);
                                if ((i < 0) || (i > 9))
                                {
                                    error = "captureDevice值超出范围";
                                    return false;
                                }
                            }
                            catch (FormatException)
                            {
                                error = "captureDevice格式错误";
                                return false;
                            }
                        }
                    }
                    #endregion

                    #region deviceID 设备编号,not must,采集设备的唯一标识编号
                    if (String.IsNullOrEmpty(deviceID) == true) { error = "deviceID不能为空"; return false; }
                    else
                    {
                        if (deviceID.Contains("_"))
                        {
                            error = "deviceID包含_字符";
                            return false;
                        }
                    }
                    #endregion

                    #region captureUser not must 采集人员,not must,当“3记录类型为”为“12监控抓拍时”指定采集人员用户名,没有设为空。
                    if (captureUser == null) { error = "captureUser不能为null"; return false; }
                    else
                    {
                        if (captureUser != "")
                        {
                            if (captureUser.Contains("_"))
                            {
                                error = "captureUser包含_字符";
                                return false;
                            }
                        }
                    }
                    #endregion

                    #region WFXWDM not must 违法行为代码,not must,本记录对应的违法行为代码,没有设为空。
                    if (WFXWDM == null) { error = "WFXWDM不能为null"; return false; }
                    else
                    {
                        if (WFXWDM != "")
                        {
                            if (WFXWDM.Contains("_"))
                            {
                                error = "WFXWDM包含_字符";
                                return false;
                            }
                        }
                    }
                    #endregion

                    #region GBDM must 路口外部编号,must,路口的国标代码,如：101010
                    if (String.IsNullOrEmpty(GBDM) == true) { error = "GBDM不能为空"; return false; }
                    else
                    {
                        if (GBDM.Contains("_"))
                        {
                            error = "GBDM包含_字符";
                            return false;
                        }
                    }
                    #endregion

                    #region BMBH must 部门编号,must,交警部门行政编号,如：3202000
                    //应为支队部门编号默认为空，暂时不验证部门编号
                    //if (String.IsNullOrEmpty(BMBH) == true) { error = "BMBH不能为空"; return false; }
                    //else
                    //{
                    //    if (BMBH.Contains("_"))
                    //    {
                    //        error = "BMBH包含_字符";
                    //        return false;
                    //    }
                    //}
                    #endregion

                    #region roadid must 路口编号,must,任意长度的路口编号
                    if (String.IsNullOrEmpty(roadid) == true) { error = "roadid不能为空"; return false; }
                    else
                    {
                        if (roadid.Contains("_"))
                        {
                            error = "roadid包含_字符";
                            return false;
                        }
                    }
                    #endregion

                    #region roadname must 路口名称,must,路口名称,不能含有_字符
                    if (String.IsNullOrEmpty(roadname) == true) { error = "roadname不能为空"; return false; }
                    else
                    {
                        if (roadname.Contains("_"))
                        {
                            error = "roadname包含_字符";
                            return false;
                        }
                    }
                    #endregion

                    #region directionID must 方向,must,1-由东向西 2-由南向北 3-由西向东 4-由北向南
                    if (String.IsNullOrEmpty(directionID) == true) { error = "directionID不能为空"; return false; }
                    else
                    {
                        if (directionID.Length > 1)
                        {
                            error = "directionID长度错误";
                            return false;
                        }
                        if (directionID.Contains("_"))
                        {
                            error = "directionID包含_字符";
                            return false;
                        }
                        try
                        {
                            int i = int.Parse(directionID);
                            if ((i < 1) || (i > 4))
                            {
                                error = "directionID值超出范围";
                                return false;
                            }
                        }
                        catch (FormatException)
                        {
                            error = "directionID格式错误";
                            return false;
                        }
                    }
                    #endregion

                    #region CD must 车道,must,由路口渠化由中间线到路边依次为1,2,3,4,5…
                    if (String.IsNullOrEmpty(CD) == true) { error = "CD不能为空"; return false; }
                    else
                    {
                        if (CD.Length > 1)
                        {
                            error = "CD长度错误";
                            return false;
                        }
                        if (CD.Contains("_"))
                        {
                            error = "CD包含_字符";
                            return false;
                        }
                        try
                        {
                            int i = int.Parse(CD);
                            if ((i < 1) || (i > 9))
                            {
                                error = "CD值超出范围";
                                return false;
                            }
                        }
                        catch (FormatException)
                        {
                            error = "CD格式错误";
                            return false;
                        }
                    }
                    #endregion

                    #region yyyy must
                    if (String.IsNullOrEmpty(yyyy) == true) { error = "yyyy不能为空"; return false; }
                    else
                    {
                        if (yyyy.Length != 4)
                        {
                            error = "yyyy长度错误";
                            return false;
                        }
                        if (yyyy.Contains("_"))
                        {
                            error = "yyyy包含_字符";
                            return false;
                        }
                        try
                        {
                            int i = int.Parse(yyyy);
                            if ((i < 2010) || (i > 2030))
                            {
                                error = "yyyy值超出范围";
                                return false;
                            }
                        }
                        catch (FormatException)
                        {
                            error = "yyyy格式错误";
                            return false;
                        }
                    }
                    #endregion

                    #region MM must
                    if (String.IsNullOrEmpty(MM) == true) { error = "MM不能为空"; return false; }
                    else
                    {
                        if (MM.Length != 2)
                        {
                            error = "MM长度错误";
                            return false;
                        }
                        if (MM.Contains("_"))
                        {
                            error = "MM包含_字符";
                            return false;
                        }
                        try
                        {
                            int i = int.Parse(MM);
                            if ((i < 1) || (i > 12))
                            {
                                error = "MM值超出范围";
                                return false;
                            }
                        }
                        catch (FormatException)
                        {
                            error = "MM格式错误";
                            return false;
                        }
                    }
                    #endregion

                    #region dd must
                    if (String.IsNullOrEmpty(dd) == true) { error = "dd不能为空"; return false; }
                    else
                    {
                        if (dd.Length != 2)
                        {
                            error = "dd长度错误";
                            return false;
                        }
                        if (dd.Contains("_"))
                        {
                            error = "dd包含_字符";
                            return false;
                        }
                        try
                        {
                            int i = int.Parse(dd);
                            if ((i < 1) || (i > 31))
                            {
                                error = "dd值超出范围";
                                return false;
                            }
                        }
                        catch (FormatException)
                        {
                            error = "dd格式错误";
                            return false;
                        }
                    }
                    #endregion

                    #region HH must
                    if (String.IsNullOrEmpty(HH) == true) { error = "HH不能为空"; return false; }
                    else
                    {
                        if (HH.Length != 2)
                        {
                            error = "HH长度错误";
                            return false;
                        }
                        if (HH.Contains("_"))
                        {
                            error = "HH包含_字符";
                            return false;
                        }
                        try
                        {
                            int i = int.Parse(HH);
                            if ((i < 0) || (i > 23))
                            {
                                error = "HH值超出范围";
                                return false;
                            }
                        }
                        catch (FormatException)
                        {
                            error = "HH格式错误";
                            return false;
                        }
                    }
                    #endregion

                    #region mm must
                    if (String.IsNullOrEmpty(mm) == true) { error = "mm不能为空"; return false; }
                    else
                    {
                        if (mm.Length != 2)
                        {
                            error = "mm长度错误";
                            return false;
                        }
                        if (mm.Contains("_"))
                        {
                            error = "mm包含_字符";
                            return false;
                        }
                        try
                        {
                            int i = int.Parse(mm);
                            if ((i < 0) || (i > 59))
                            {
                                error = "mm值超出范围";
                                return false;
                            }
                        }
                        catch (FormatException)
                        {
                            error = "mm格式错误";
                            return false;
                        }
                    }
                    #endregion

                    #region ss must
                    if (String.IsNullOrEmpty(ss) == true) { error = "ss不能为空"; return false; }
                    else
                    {
                        if (ss.Length != 2)
                        {
                            error = "ss长度错误";
                            return false;
                        }
                        if (ss.Contains("_"))
                        {
                            error = "ss包含_字符";
                            return false;
                        }
                        try
                        {
                            int i = int.Parse(ss);
                            if ((i < 0) || (i > 59))
                            {
                                error = "ss值超出范围";
                                return false;
                            }
                        }
                        catch (FormatException)
                        {
                            error = "ss格式错误";
                            return false;
                        }
                    }
                    #endregion

                    #region fff must
                    if (String.IsNullOrEmpty(fff) == true) { error = "fff不能为空"; return false; }
                    else
                    {
                        if (fff.Length != 3)
                        {
                            error = "fff长度错误";
                            return false;
                        }
                        if (fff.Contains("_"))
                        {
                            error = "fff包含_字符";
                            return false;
                        }
                        try
                        {
                            int i = int.Parse(fff);
                            if ((i < 0) || (i > 999))
                            {
                                error = "fff值超出范围";
                                return false;
                            }
                        }
                        catch (FormatException)
                        {
                            error = "fff格式错误";
                            return false;
                        }
                    }
                    #endregion

                    #region RedLightBeginTime not must红灯开始时间,not must,格式为：yyyy-MM-dd hh:mm:ss,由检测器给出时间
                    if (RedLightBeginTime == null) { error = "RedLightBeginTime不能为null"; return false; }
                    else
                    {
                        if (RedLightBeginTime != "")
                        {
                            if (RedLightBeginTime.Length != 19)
                            {
                                error = "RedLightBeginTime长度错误";
                                return false;
                            }
                            if (RedLightBeginTime.Contains("_"))
                            {
                                error = "RedLightBeginTime包含_字符";
                                return false;
                            }
                        }
                    }
                    #endregion

                    #region RedLightDuration not must 红灯持续时间,not must,单位秒,由检测器给出时间
                    if (RedLightDuration == null) { error = "RedLightDuration不能为null"; return false; }
                    else
                    {
                        if (RedLightDuration != "")
                        {
                            if (RedLightBeginTime.Contains("_"))
                            {
                                error = "RedLightDuration包含_字符";
                                return false;
                            }
                        }
                        else
                        {
                            error = "RedLightDuration不能为空,默认值为0";
                            return false;
                        }
                    }

                    #endregion

                    #region plateType not must车牌类型0---标准民用与军车车牌1---02 式民用车牌2---军警车牌3---警车车牌4---民用车双行尾牌
                    if (plateType == null) { error = "plateType不能为null"; return false; }
                    else
                    {
                        //暂时不验证
                        //if (plateType != "")
                        //{

                        //    try
                        //    {
                        //        if (plateType.Length != 1)
                        //        {
                        //            error = "plateType长度错误";
                        //            return false;
                        //        }
                        //        if (plateType.Contains("_"))
                        //        {
                        //            error = "plateType包含_字符";
                        //            return false;
                        //        }
                        //        int i = int.Parse(plateType);
                        //        if ((i < 0) || (i > 4))
                        //        {
                        //            error = "plateType值超出范围";
                        //            return false;
                        //        }

                        //    }
                        //    catch (FormatException)
                        //    {
                        //        error = "plateType格式错误";
                        //        return false;
                        //    }

                        //}
                    }
                    #endregion

                    #region plateColor not must 车牌颜色,not must,蓝 黄 白 黑,没有为空字符串
                    if (plateColor == null) { error = "plateColor不能为null"; return false; }
                    else
                    {
                        if (plateColor != "")
                        {

                            if (plateColor.Length != 1)
                            {
                                error = "plateColor长度错误";
                                return false;
                            }
                            if (plateColor.Contains("_"))
                            {
                                error = "plateColor包含_字符";
                                return false;
                            }

                            if ((plateColor != "蓝") && (plateColor != "黄") && (plateColor != "白") && (plateColor != "黑"))
                            {
                                error = "plateColor值超出范围";
                                return false;
                            }

                        }


                    }

                    #endregion

                    #region HPHM 车牌号,not must,车牌的汉字和大写字母以及数字部分,没有为空字符串
                    if (HPHM == null)
                    {
                        error = "HPHM不能为null";
                        return false;
                    }
                    else
                    {
                        if (HPHM != "")
                        {


                            if (HPHM.Contains("_"))
                            {
                                error = "HPHM包含_字符";
                                return false;
                            }



                        }


                    }




                    #endregion

                    #region bodyColor 车身颜色,not must,0-其他色 1-白色 2-银色 3-灰色 4-黑色 5-红色 6-深蓝7-蓝色 8-黄色 9-绿色 10-棕色 11-粉色 12-紫色,没有为空字符串
                    if (bodyColor == null) { error = "bodyColor不能为null"; return false; }
                    else
                    {
                        if (bodyColor != "")
                        {
                            if (bodyColor.Length > 3)
                            {
                                error = "bodyColor长度错误";
                                return false;
                            }
                            if (bodyColor.Contains("_"))
                            {
                                error = "bodyColor包含_字符";
                                return false;
                            }
                            try
                            {
                                int i = int.Parse(bodyColor);
                                if ((i < 0) || (i > 255))
                                {
                                    error = "bodyColor值超出范围";
                                    return false;
                                }
                            }
                            catch (FormatException)
                            {
                                error = "bodyColor格式错误";
                                return false;
                            }
                        }
                    }
                    #endregion

                    #region speedLimit not must 限速,not must,无限速为空字符串
                    if (speedLimit == null) { error = "speedLimit不能为null"; return false; }
                    else
                    {
                        if (speedLimit != "")
                        {
                            if (speedLimit.Length > 5)
                            {
                                error = "speedLimit长度错误";
                                return false;
                            }
                            if (speedLimit.Contains("_"))
                            {
                                error = "speedLimit包含_字符";
                                return false;
                            }
                            try
                            {
                                int i = int.Parse(speedLimit);
                                if ((i < 0) || (i > 99999))
                                {
                                    error = "speedLimit值超出范围";
                                    return false;
                                }
                            }
                            catch (FormatException)
                            {
                                error = "speedLimit格式错误";
                                return false;
                            }
                        }
                    }
                    #endregion

                    #region speed not must 车速,not must,无车速为空字符串
                    //if(String.IsNullOrEmpty(speed)==true){error = "SnapCount不能为空";return false;}
                    if (speed == null) { error = "speed不能为null"; return false; }
                    else
                    {
                        if (speed != "")
                        {
                            if (speed.Length > 5)
                            {
                                error = "speed长度错误";
                                return false;
                            }
                            if (speed.Contains("_"))
                            {
                                error = "speed包含_字符";
                                return false;
                            }
                            try
                            {
                                int i = int.Parse(speed);
                                if ((i < 0) || (i > 99999))
                                {
                                    error = "speed值超出范围";
                                    return false;
                                }
                            }
                            catch (FormatException)
                            {
                                error = "speed格式错误";
                                return false;
                            }
                        }
                    }
                    #endregion

                    #region PIC1 must 图片1路径,如http://172.16.22.2/卡口/某某路口/2014/05/09/6511-20140505101010-555-3-1.jpg
                    if (String.IsNullOrEmpty(PIC1) == true) { error = "PIC1不能为空"; return false; }
                    else
                    {
                        if (PIC1.Contains("_"))
                        {
                            error = "PIC1包含_字符";
                            return false;
                        }
                        if (!PIC1.ToLower().EndsWith(".jpg"))
                        {
                            error = "PIC1扩展名错误";
                            return false;
                        }
                        if (withpic)
                        {
                            if (PIC1.Contains(":") || PIC1.Contains("/") || PIC1.Contains("\\"))
                            {
                                error = "上传图片数据时,PIC1为不含路径图片名";
                                return false;
                            }
                        }
                        else
                        {
                            if (recordType == "0")
                            {
                                if (gKKDB == "AITMS")
                                {
                                    if (PIC1.Contains("C:") || PIC1.Contains("D:") || PIC1.Contains("E:") || PIC1.Contains("F:")||
                                        PIC1.Contains("G:") || PIC1.Contains("H:") || PIC1.Contains("I:") || PIC1.Contains("J:")||
                                        PIC1.Contains("K:") || PIC1.Contains("L:") || PIC1.Contains("M:") || PIC1.Contains("N:"))
                                    {
                                        error = "AITMS库的PIC1路径不能是FILE";
                                        return false;
                                    }
                                }
                                else if (gKKDB == "KAKOU")
                                {
                                    if (PIC1.StartsWith("http") ||PIC1.StartsWith("HTTP") || PIC1.StartsWith("ftp") ||PIC1.StartsWith("FTP"))
                                    {
                                        error = "KAKOU库的路径PIC1不能是HTTP或FTP";
                                        return false;
                                    }
                                }
                                else
                                {
                                    error = "kdws数据库类型KKDB配置错误";
                                    return false;
                                }
                            }
                            else
                            {
                                if (gDJDB == "AITMS")
                                {
                                    if (PIC1.Contains("C:") || PIC1.Contains("D:") || PIC1.Contains("E:") || PIC1.Contains("F:")||
                                        PIC1.Contains("G:") || PIC1.Contains("H:") || PIC1.Contains("I:") || PIC1.Contains("J:")||
                                        PIC1.Contains("K:") || PIC1.Contains("L:") || PIC1.Contains("M:") || PIC1.Contains("N:"))
                                    {
                                        error = "AITMS库的PIC1路径不能是FILE";
                                        return false;
                                    }
                                }
                                else if (gDJDB == "WFCLXT")
                                {
                                    if (PIC1.StartsWith("http") || PIC1.StartsWith("HTTP") || PIC1.StartsWith("ftp") || PIC1.StartsWith("FTP"))
                                    {
                                        error = "WFCLXT库的PIC1路径不能是HTTP或FTP";
                                        return false;
                                    }
                                }
                                else
                                {
                                    error = "kdws数据库类型DJDB配置错误";
                                    return false;
                                }
                            }
                            
                        }
                    }
                    #endregion

                    #region PIC2 not must 图片2路径,如http://172.16.22.2/卡口/某某路口/2014/05/09/6511-20140505101010-555-3-2.jpg
                    if (PIC2 == null) { error = "PIC2不能为null"; return false; }
                    else if ((PIC2 == "") && (recordType != "0") && (gDJDB == "WFCLXT")) { error = "WFCLXT的PIC2不能为空"; return false; }
                    else
                    {
                        if (PIC2 != "")
                        {
                            if (PIC2.Contains("_"))
                            {
                                error = "PIC2包含_字符";
                                return false;
                            }
                            if (!PIC2.ToLower().EndsWith(".jpg"))
                            {
                                error = "PIC2扩展名错误";
                                return false;
                            }
                            if (withpic)
                            {
                                if (PIC2.Contains(":") || PIC2.Contains("/") || PIC2.Contains("\\"))
                                {
                                    error = "上传图片数据时,PIC2为不含路径图片名";
                                    return false;
                                }
                            }
                            else
                            {
                                if (recordType == "0")
                                {
                                    if (gKKDB == "AITMS")
                                    {
                                        if (PIC2.Contains("C:") || PIC2.Contains("D:") || PIC2.Contains("E:") || PIC2.Contains("F:")||
                                        PIC2.Contains("G:") || PIC2.Contains("H:") || PIC2.Contains("I:") || PIC2.Contains("J:")||
                                        PIC2.Contains("K:") || PIC2.Contains("L:") || PIC2.Contains("M:") || PIC2.Contains("N:"))
                                        {
                                            error = "AITMS库的PIC2路径不能是FILE";
                                            return false;
                                        }
                                    }
                                    else if (gKKDB == "KAKOU")
                                    {
                                        if (PIC2.StartsWith("http") || PIC2.StartsWith("HTTP") || PIC2.StartsWith("ftp") || PIC2.StartsWith("FTP"))
                                        {
                                            error = "KAKOU库的路径PIC2不能是HTTP或FTP";
                                            return false;
                                        }
                                    }
                                    else
                                    {
                                        error = "kdws数据库类型KKDB配置错误";
                                        return false;
                                    }
                                }
                                else
                                {
                                    if (gDJDB == "AITMS")
                                    {
                                        if (PIC2.Contains("C:") || PIC2.Contains("D:") || PIC2.Contains("E:") || PIC2.Contains("F:")||
                                        PIC2.Contains("G:") || PIC2.Contains("H:") || PIC2.Contains("I:") || PIC2.Contains("J:")||
                                        PIC2.Contains("K:") || PIC2.Contains("L:") || PIC2.Contains("M:") || PIC2.Contains("N:"))
                                        {
                                            error = "AITMS库的PIC2路径不能是FILE";
                                            return false;
                                        }
                                    }
                                    else if (gDJDB == "WFCLXT")
                                    {
                                        if (PIC2.StartsWith("http") || PIC2.StartsWith("HTTP") || PIC2.StartsWith("ftp") || PIC2.StartsWith("FTP"))
                                        {
                                            error = "WFCLXT库的PIC2路径不能是HTTP或FTP";
                                            return false;
                                        }
                                    }
                                    else
                                    {
                                        error = "kdws数据库类型DJDB配置错误";
                                        return false;
                                    }
                                }
                            }
                        }
                    }
                    #endregion

                    #region 图片3路径,如http://172.16.22.2/卡口/某某路口/2014/05/09/6511-20140505101010-555-3-3.jpg
                    if (PIC3 == null) { error = "PIC3不能为null"; return false; }
                    else if ((PIC3 == "") && (recordType!="0")&&(gDJDB == "WFCLXT")) { error = "WFCLXT的PIC3不能为空"; return false; }
                    else
                    {
                        if (PIC3 != "")
                        {
                            if (PIC3.Contains("_"))
                            {
                                error = "PIC3包含_字符";
                                return false;
                            }
                            if (!PIC3.ToLower().EndsWith(".jpg"))
                            {
                                error = "PIC3扩展名错误";
                                return false;
                            }
                            if (withpic)
                            {
                                if (PIC3.Contains(":") || PIC3.Contains("/") || PIC3.Contains("\\"))
                                {
                                    error = "上传图片数据时,PIC3为不含路径图片名";
                                    return false;
                                }
                            }
                            else
                            {
                                if (recordType == "0")
                                {
                                    if (gKKDB == "AITMS")
                                    {
                                        if (PIC3.Contains("C:") || PIC3.Contains("D:") || PIC3.Contains("E:") || PIC3.Contains("F:")||
                                        PIC3.Contains("G:") || PIC3.Contains("H:") || PIC3.Contains("I:") || PIC3.Contains("J:")||
                                        PIC3.Contains("K:") || PIC3.Contains("L:") || PIC3.Contains("M:") || PIC3.Contains("N:"))
                                        {
                                            error = "AITMS库的PIC3路径不能是FILE";
                                            return false;
                                        }
                                    }
                                    else if (gKKDB == "KAKOU")
                                    {
                                        if (PIC3.StartsWith("http") || PIC3.StartsWith("HTTP") || PIC3.StartsWith("ftp") || PIC3.StartsWith("FTP"))
                                        {
                                            error = "KAKOU库的路径PIC3不能是HTTP或FTP";
                                            return false;
                                        }
                                    }
                                    else
                                    {
                                        error = "kdws数据库类型KKDB配置错误";
                                        return false;
                                    }
                                }
                                else
                                {
                                    if (gDJDB == "AITMS")
                                    {
                                        if(PIC3.Contains("C:") || PIC3.Contains("D:") || PIC3.Contains("E:") || PIC3.Contains("F:")||
                                        PIC3.Contains("G:") || PIC3.Contains("H:") || PIC3.Contains("I:") || PIC3.Contains("J:")||
                                        PIC3.Contains("K:") || PIC3.Contains("L:") || PIC3.Contains("M:") || PIC3.Contains("N:"))
                                        {
                                            error = "AITMS库的PIC3路径不能是FILE";
                                            return false;
                                        }
                                    }
                                    else if (gDJDB == "WFCLXT")
                                    {
                                        if (PIC3.StartsWith("http") || PIC3.StartsWith("HTTP") || PIC3.StartsWith("ftp") || PIC3.StartsWith("FTP"))
                                        {
                                            error = "WFCLXT库的PIC3路径不能是HTTP或FTP";
                                            return false;
                                        }
                                    }
                                    else
                                    {
                                        error = "kdws数据库类型DJDB配置错误";
                                        return false;
                                    }
                                }
                            }
                        }
                    }
                    #endregion

                    #region 图片4路径,备用
                    if (PIC4 == null) { error = "PIC4不能为null"; return false; }
                    else
                    {
                        if (PIC4 != "")
                        {
                            if (PIC4.Contains("_"))
                            {
                                error = "PIC4包含_字符";
                                return false;
                            }
                            if (!PIC4.ToLower().EndsWith(".jpg"))
                            {
                                error = "PIC4扩展名错误";
                                return false;
                            }
                            if (withpic)
                            {
                                if (PIC4.Contains(":") || PIC4.Contains("/") || PIC4.Contains("\\"))
                                {
                                    error = "上传图片数据时,PIC4为不含路径图片名";
                                    return false;
                                }
                            }
                            else
                            {
                                if (recordType == "0")
                                {
                                    if (gKKDB == "AITMS")
                                    {
                                        if(PIC4.Contains("C:") || PIC4.Contains("D:") || PIC4.Contains("E:") || PIC4.Contains("F:")||
                                        PIC4.Contains("G:") || PIC4.Contains("H:") || PIC4.Contains("I:") || PIC4.Contains("J:")||
                                        PIC4.Contains("K:") || PIC4.Contains("L:") || PIC4.Contains("M:") || PIC4.Contains("N:"))
                                        {
                                            error = "AITMS库的PIC4路径不能是FILE";
                                            return false;
                                        }
                                    }
                                    else if (gKKDB == "KAKOU")
                                    {
                                        if (PIC4.StartsWith("http") || PIC4.StartsWith("HTTP") || PIC4.StartsWith("ftp") || PIC4.StartsWith("FTP"))
                                        {
                                            error = "KAKOU库的路径PIC4不能是HTTP或FTP";
                                            return false;
                                        }
                                    }
                                    else
                                    {
                                        error = "kdws数据库类型KKDB配置错误";
                                        return false;
                                    }
                                }
                                else
                                {
                                    if (gDJDB == "AITMS")
                                    {
                                        if(PIC4.Contains("C:") || PIC4.Contains("D:") || PIC4.Contains("E:") || PIC4.Contains("F:")||
                                        PIC4.Contains("G:") || PIC4.Contains("H:") || PIC4.Contains("I:") || PIC4.Contains("J:")||
                                        PIC4.Contains("K:") || PIC4.Contains("L:") || PIC4.Contains("M:") || PIC4.Contains("N:"))
                                        {
                                            error = "AITMS库的PIC4路径不能是FILE";
                                            return false;
                                        }
                                    }
                                    else if (gDJDB == "WFCLXT")
                                    {
                                        if (PIC4.StartsWith("http") || PIC4.StartsWith("HTTP") || PIC4.StartsWith("ftp") || PIC4.StartsWith("FTP"))
                                        {
                                            error = "WFCLXT库的PIC4路径不能是HTTP或FTP";
                                            return false;
                                        }
                                    }
                                    else
                                    {
                                        error = "kdws数据库类型DJDB配置错误";
                                        return false;
                                    }
                                }
                            }
                        }
                    }
                    #endregion

                    #region 压缩图片路径,如http://172.16.22.2/卡口/某某路口/2014/05/09/6511-20140505101010-555-1-1zoom.jpg
                    if (PICZoom == null) { error = "PICZoom不能为null"; return false; }
                    else
                    {
                        if (PICZoom != "")
                        {
                            if (PICZoom.Contains("_"))
                            {
                                error = "PICZoom包含_字符";
                                return false;
                            }
                            if (!PICZoom.ToLower().EndsWith(".jpg"))
                            {
                                error = "PICZoom扩展名错误";
                                return false;
                            }
                            if (withpic)
                            {
                                if (PICZoom.Contains(":") || PICZoom.Contains("/") || PICZoom.Contains("\\"))
                                {
                                    error = "上传图片数据时,PICZoom为不含路径图片名";
                                    return false;
                                }
                            }
                            else
                            {
                                if (recordType == "0")
                                {
                                    if (gKKDB == "AITMS")
                                    {
                                        if(PICZoom.Contains("C:") || PICZoom.Contains("D:") || PICZoom.Contains("E:") || PICZoom.Contains("F:")||
                                        PICZoom.Contains("G:") || PICZoom.Contains("H:") || PICZoom.Contains("I:") || PICZoom.Contains("J:")||
                                        PICZoom.Contains("K:") || PICZoom.Contains("L:") || PICZoom.Contains("M:") || PICZoom.Contains("N:"))
                                        {
                                            error = "AITMS库的PICZoom路径不能是FILE";
                                            return false;
                                        }
                                    }
                                    else if (gKKDB == "KAKOU")
                                    {
                                        if (PICZoom.StartsWith("http") || PICZoom.StartsWith("HTTP") || PICZoom.StartsWith("ftp") || PICZoom.StartsWith("FTP"))
                                        {
                                            error = "KAKOU库的路径PICZoom不能是HTTP或FTP";
                                            return false;
                                        }
                                    }
                                    else
                                    {
                                        error = "kdws数据库类型KKDB配置错误";
                                        return false;
                                    }
                                }
                                else
                                {
                                    if (gDJDB == "AITMS")
                                    {
                                        if(PICZoom.Contains("C:") || PICZoom.Contains("D:") || PICZoom.Contains("E:") || PICZoom.Contains("F:")||
                                        PICZoom.Contains("G:") || PICZoom.Contains("H:") || PICZoom.Contains("I:") || PICZoom.Contains("J:")||
                                        PICZoom.Contains("K:") || PICZoom.Contains("L:") || PICZoom.Contains("M:") || PICZoom.Contains("N:"))
                                        {
                                            error = "AITMS库的PICZoom路径不能是FILE";
                                            return false;
                                        }
                                    }
                                    else if (gDJDB == "WFCLXT")
                                    {
                                        if (PICZoom.StartsWith("http") || PICZoom.StartsWith("HTTP") || PICZoom.StartsWith("ftp") || PICZoom.StartsWith("FTP"))
                                        {
                                            error = "WFCLXT库的PICZoom路径不能是HTTP或FTP";
                                            return false;
                                        }
                                    }
                                    else
                                    {
                                        error = "kdws数据库类型DJDB配置错误";
                                        return false;
                                    }
                                }
                            }
                        }
                    }
                    #endregion

                    #region 车牌图片路径,如http://172.16.22.2/卡口/某某路口/2014/05/09/6511-20140505101010-555-1-1plate.jpg
                    if (PICPlate == null) { error = "PICPlate不能为null"; return false; }
                    else
                    {
                        if (PICPlate != "")
                        {
                            if (PICPlate.Contains("_"))
                            {
                                error = "PICPlate包含_字符";
                                return false;
                            }
                            if (!PICPlate.ToLower().EndsWith(".jpg"))
                            {
                                error = "PICPlate扩展名错误";
                                return false;
                            }
                            if (withpic)
                            {
                                if (PICPlate.Contains(":") || PICPlate.Contains("/") || PICPlate.Contains("\\"))
                                {
                                    error = "上传图片数据时,PICPlate为不含路径图片名";
                                    return false;
                                }
                            }
                            else
                            {
                                if (recordType == "0")
                                {
                                    if (gKKDB == "AITMS")
                                    {
                                        if(PICPlate.Contains("C:") || PICPlate.Contains("D:") || PICPlate.Contains("E:") || PICPlate.Contains("F:")||
                                        PICPlate.Contains("G:") || PICPlate.Contains("H:") || PICPlate.Contains("I:") || PICPlate.Contains("J:")||
                                        PICPlate.Contains("K:") || PICPlate.Contains("L:") || PICPlate.Contains("M:") || PICPlate.Contains("N:"))
                                        {
                                            error = "AITMS库的PICPlate路径不能是FILE";
                                            return false;
                                        }
                                    }
                                    else if (gKKDB == "KAKOU")
                                    {
                                        if (PICPlate.StartsWith("http") || PICPlate.StartsWith("HTTP") || PICPlate.StartsWith("ftp") || PICPlate.StartsWith("FTP"))
                                        {
                                            error = "KAKOU库的路径PICPlate不能是HTTP或FTP";
                                            return false;
                                        }
                                    }
                                    else
                                    {
                                        error = "kdws数据库类型KKDB配置错误";
                                        return false;
                                    }
                                }
                                else
                                {
                                    if (gDJDB == "AITMS")
                                    {
                                        if(PICPlate.Contains("C:") || PICPlate.Contains("D:") || PICPlate.Contains("E:") || PICPlate.Contains("F:")||
                                        PICPlate.Contains("G:") || PICPlate.Contains("H:") || PICPlate.Contains("I:") || PICPlate.Contains("J:")||
                                        PICPlate.Contains("K:") || PICPlate.Contains("L:") || PICPlate.Contains("M:") || PICPlate.Contains("N:"))
                                        {
                                            error = "AITMS库的PICPlate路径不能是FILE";
                                            return false;
                                        }
                                    }
                                    else if (gDJDB == "WFCLXT")
                                    {
                                        if (PICPlate.StartsWith("http") || PICPlate.StartsWith("HTTP") || PICPlate.StartsWith("ftp") || PICPlate.StartsWith("FTP"))
                                        {
                                            error = "WFCLXT库的PICPlate路径不能是HTTP或FTP";
                                            return false;
                                        }
                                    }
                                    else
                                    {
                                        error = "kdws数据库类型DJDB配置错误";
                                        return false;
                                    }
                                }
                            }
                        }
                    }
                    #endregion

                    #region PIC1Bytes
                    if (withpic)
                    {
                        if (PIC1Bytes == null)
                        {
                            error = "PIC1Bytes为null";
                            return false;
                        }
                        else
                        {
                            if (PIC1Bytes.Length < 10)
                            {
                                error = "PIC1Bytes<10";
                                return false;
                            }
                        }
                    }
                    #endregion

                    #region PIC2Bytes
                    if (withpic)
                    {
                        if ((gDJDB == "WFCLXT")&&(recordType!="0"))
                        {
                            if (PIC2Bytes == null)
                            {
                                error = "PIC2Bytes为null";
                                return false;
                            }
                            else
                            {
                                if (PIC2Bytes.Length < 10)
                                {
                                    error = "PIC2Bytes<10";
                                    return false;
                                }
                            }
                        }
                    }
                    #endregion

                    #region PIC3Bytes
                    if (withpic)
                    {
                        if((gDJDB == "WFCLXT")&&(recordType!="0"))
                        {
                            if (PIC3Bytes == null)
                            {
                                error = "PIC3Bytes为null";
                                return false;
                            }
                            else
                            {
                                if (PIC3Bytes.Length < 10)
                                {
                                    error = "PIC3Bytes<10";
                                    return false;
                                }
                            }
                        }
                    }
                    #endregion

                    #endregion
                }
                catch (Exception er)
                {
                    error = "参数校验出现异常" + er.Message;
                    return false;
                }

                string path = "";
                string path1 = "";
                string path2 = "";
                string path3 = "";
                string path4 = "";
                string path5 = "";
                string path6 = "";

                RecordParam record = new RecordParam();
                record.SnapCount = SnapCount;
                record.picJionMode = picJionMode;
                record.recordType = recordType;
                record.Company = Company;
                record.captureDevice = captureDevice;
                record.deviceID = deviceID;
                record.captureUser = captureUser;
                record.WFXWDM = WFXWDM;
                record.GBDM = GBDM;
                record.BMBH = BMBH;
                record.roadid = roadid;
                record.roadname = roadname;
                record.directionID = directionID;
                record.CD = CD;
                record.JGSJ = yyyy + MM + dd + HH + mm + ss + fff;
                record.RedLightBeginTime = RedLightBeginTime;
                record.RedLightDuration = RedLightDuration;
                record.plateType = plateType;
                record.ManuelCarType = plateType;//监控抓拍借用
                record.plateColor = plateColor;
                record.HPHM = HPHM;
                record.bodyColor = bodyColor;
                record.speedLimit = speedLimit;
                record.speed = speed;
                if (withpic == false)
                {
                    record.PIC1 = PIC1;
                    record.PIC2 = PIC2;
                    record.PIC3 = PIC3;
                    record.PIC4 = PIC4;
                    record.PICZoom = PICZoom;
                    record.PICPlate = PICPlate;
                }
                else
                {
                    try
                    {
                        #region 图片保存
                        if (recordType == "0")//卡口
                        {
                            path = gKKIISPath + "\\" + roadname + "\\" + yyyy + "\\" + MM + "\\" + dd;
                        }
                        else
                        {
                            path = gDJIISPath + "\\" + roadname + "\\" + yyyy + "\\" + MM + "\\" + dd;
                        }
                        if (!Directory.Exists(path)) Directory.CreateDirectory(path);
                        path1 = ((PIC1 == "") ? "" : (path + "\\" + PIC1));
                        path2 = ((PIC2 == "") ? "" : (path + "\\" + PIC2));
                        path3 = ((PIC3 == "") ? "" : (path + "\\" + PIC3));
                        path4 = ((PIC4 == "") ? "" : (path + "\\" + PIC4));
                        path5 = ((PICZoom == "") ? "" : (path + "\\" + PICZoom));
                        path6 = ((PICPlate == "") ? "" : (path + "\\" + PICPlate));


                        if (PIC1Bytes != null) File.WriteAllBytes(path1, PIC1Bytes);
                        if (PIC2Bytes != null) File.WriteAllBytes(path2, PIC2Bytes);
                        if (PIC3Bytes != null) File.WriteAllBytes(path3, PIC3Bytes);
                        if (PIC4Bytes != null) File.WriteAllBytes(path4, PIC4Bytes);
                        if (PICZoomBytes != null) File.WriteAllBytes(path5, PICZoomBytes);
                        if (PICPlateBytes != null) File.WriteAllBytes(path6, PICPlateBytes);

                        if (recordType == "0")//卡口
                        {
                            if (gKKDB == "AITMS")
                            {
                                record.PIC1 = GetIISPath(gIndexMode, path1, gLocalIP, gKKIISName, gKKIISPath);
                                record.PIC2 = GetIISPath(gIndexMode, path2, gLocalIP, gKKIISName, gKKIISPath);
                                record.PIC3 = GetIISPath(gIndexMode, path3, gLocalIP, gKKIISName, gKKIISPath);
                                record.PIC4 = GetIISPath(gIndexMode, path4, gLocalIP, gKKIISName, gKKIISPath);
                                record.PICZoom = GetIISPath(gIndexMode, path5, gLocalIP, gKKIISName, gKKIISPath);
                                record.PICPlate = GetIISPath(gIndexMode, path6, gLocalIP, gKKIISName, gKKIISPath);
                            }
                            else if (gKKDB == "KAKOU")
                            {
                                record.PIC1 = path1;
                                record.PIC2 = path2;
                                record.PIC3 = path3;
                                record.PIC4 = path4;
                                record.PICZoom = path5;
                                record.PICPlate = path6;
                            }

                        }
                        else//电警
                        {
                            if (gDJDB == "AITMS")
                            {
                                record.PIC1 = GetIISPath(gIndexMode, path1, gLocalIP, gDJIISName, gDJIISPath);
                                record.PIC2 = GetIISPath(gIndexMode, path2, gLocalIP, gDJIISName, gDJIISPath);
                                record.PIC3 = GetIISPath(gIndexMode, path3, gLocalIP, gDJIISName, gDJIISPath);
                                record.PIC4 = GetIISPath(gIndexMode, path4, gLocalIP, gDJIISName, gDJIISPath);
                                record.PICZoom = GetIISPath(gIndexMode, path5, gLocalIP, gDJIISName, gDJIISPath);
                                record.PICPlate = GetIISPath(gIndexMode, path6, gLocalIP, gDJIISName, gDJIISPath);
                            }
                            else if (gDJDB == "WFCLXT")
                            {
                                record.PIC1 = path1;
                                record.PIC2 = path2;
                                record.PIC3 = path3;
                                record.PIC4 = path4;
                                record.PICZoom = path5;
                                record.PICPlate = path6;
                            }

                        }

                        #endregion
                    }
                    catch (Exception er)
                    {
                        error = "图片保存出现异常" + er.Message;
                        return false;
                    }

                }

                try
                {
                    if (m_client != null)
                    {
                        lock (m_client)
                        {
                            m_client.TryConnect();
                            ans = m_client.UPLoad(record);
                            return ans;
                        }
                    }
                }
                catch (Exception er)
                {
                    error = "图片上传出现异常" + er.Message;
                    return false;
                }
            }
            catch (Exception er)
            {
                ans = false;
                error = "Upload()异常" + er.Message;
            }
            return ans;
        }

        /// <summary>
        /// 销毁资源
        /// </summary>
        /// <param name="disposing">disposing</param>
        protected override void Dispose(bool disposing)
        {
            try
            {
                if (m_client != null)
                {
                    m_client.Close();
                }
            }
            catch { }

            try
            {
                base.Dispose(disposing);
            }
            catch { }
        }

        /// <summary>
        /// 生成图片网络路径
        /// </summary>
        /// <param name="head">协议头ftp,http</param>
        /// <param name="fullFileName">图片含路径全名</param>
        /// <param name="IISIP">IIS服务器的访问IP</param>
        /// <param name="IISName">IIS虚拟目录名称</param>
        /// <param name="IISPath">IIS虚拟目录文件夹</param>
        /// <returns>图片网络路径</returns>
        private string GetIISPath(string head, string fullFileName, string IISIP, string IISName, string IISPath)
        {
            string ans = "";
            try
            {
                if (fullFileName != "")
                {
                    ans = head + "://" + IISIP + "/" + IISName + fullFileName.Replace(IISPath, "").Replace("\\", "/");
                }
            }
            catch { ans = ""; }
            return ans;
        }


        /// <summary>
        /// 仅上传图片到服务器（连云港港口需求）
        /// </summary>
        /// <param name="recordType">must,记录类型,0-卡口,1-低速,2-超速,3-逆行,4-违反交通灯指示,5-压车道线,6-不按导向,7-路口滞留,8-机占非,9-违法变道,10-机动车违反规定使用专用车道,11-黄牌车禁限,12-监控抓拍</param>
        /// <param name="roadname">must,路口名称,不能含有_字符</param>
        /// <param name="yyyy">must,年,4位</param>
        /// <param name="MM">must,月,2位</param>
        /// <param name="dd">must,日,2位</param>
        /// <param name="PIC1">must,图片1,为不含路径图片名</param>
        /// <param name="PIC2">not must,图片2,为不含路径图片名</param>
        /// <param name="PIC3">not must,图片3,为不含路径图片名</param>
        /// <param name="PIC4">not must,图片4,为不含路径图片名</param>
        /// <param name="PICZoom">not must,缩略图或压缩图,为不含路径图片名</param>
        /// <param name="PICPlate">not must,车牌图,为不含路径图片名</param>
        /// <param name="PIC1Bytes">withpic=true时must,图片1数据byte[]</param>
        /// <param name="PIC2Bytes">not must,图片2数据byte[]</param>
        /// <param name="PIC3Bytes">not must,图片3数据byte[]</param>
        /// <param name="PIC4Bytes">not must,图片4数据byte[]</param>
        /// <param name="PICZoomBytes">not must,缩略图数据byte[]</param>
        /// <param name="PICPlateBytes">not must,车牌图片数据byte[]</param>
        /// <param name="error">错误描述</param>
        /// <returns>上传结果,true-成功false-失败</returns>
        [WebMethod]
        public bool UploadPicOnly(string recordType, string roadname, string yyyy, string MM, string dd,
            string PIC1, string PIC2, string PIC3, string PIC4, string PICZoom, string PICPlate,
            byte[] PIC1Bytes, byte[] PIC2Bytes, byte[] PIC3Bytes, byte[] PIC4Bytes, byte[] PICZoomBytes,
            byte[] PICPlateBytes, out string error)
        {
            bool ans = false;
            error = "";
            try
            {
                try
                {
                    #region 参数校验
                    #region recordType must 记录类型,must,0-卡口,1-低速,2-超速,3-逆行,4-违反交通灯指示,5-压车道线,6-不按导向,7-路口滞留,8-机占非,9-违法变道,10-机动车违反规定使用专用车道,11-黄牌车禁限,12-监控抓拍
                    if (String.IsNullOrEmpty(recordType) == true) { error = "recordType不能为空"; return false; }
                    else
                    {
                        if (recordType.Length > 2)
                        {
                            error = "recordType长度错误";
                            return false;
                        }
                        if (recordType.Contains("_"))
                        {
                            error = "recordType包含_字符";
                            return false;
                        }
                        try
                        {
                            int i = int.Parse(recordType);
                            if ((i < 0) || (i > 12))
                            {
                                error = "recordType值超出范围";
                                return false;
                            }
                        }
                        catch (FormatException)
                        {
                            error = "recordType格式错误";
                            return false;
                        }
                    }
                    #endregion

                    #region roadname must 路口名称,must,路口名称,不能含有_字符
                    if (String.IsNullOrEmpty(roadname) == true) { error = "roadname不能为空"; return false; }
                    else
                    {
                        if (roadname.Contains("_"))
                        {
                            error = "roadname包含_字符";
                            return false;
                        }
                    }
                    #endregion

                    #region yyyy must
                    if (String.IsNullOrEmpty(yyyy) == true) { error = "yyyy不能为空"; return false; }
                    else
                    {
                        if (yyyy.Length != 4)
                        {
                            error = "yyyy长度错误";
                            return false;
                        }
                        if (yyyy.Contains("_"))
                        {
                            error = "yyyy包含_字符";
                            return false;
                        }
                        try
                        {
                            int i = int.Parse(yyyy);
                            if ((i < 2010) || (i > 2030))
                            {
                                error = "yyyy值超出范围";
                                return false;
                            }
                        }
                        catch (FormatException)
                        {
                            error = "yyyy格式错误";
                            return false;
                        }
                    }
                    #endregion

                    #region MM must
                    if (String.IsNullOrEmpty(MM) == true) { error = "MM不能为空"; return false; }
                    else
                    {
                        if (MM.Length != 2)
                        {
                            error = "MM长度错误";
                            return false;
                        }
                        if (MM.Contains("_"))
                        {
                            error = "MM包含_字符";
                            return false;
                        }
                        try
                        {
                            int i = int.Parse(MM);
                            if ((i < 1) || (i > 12))
                            {
                                error = "MM值超出范围";
                                return false;
                            }
                        }
                        catch (FormatException)
                        {
                            error = "MM格式错误";
                            return false;
                        }
                    }
                    #endregion

                    #region dd must
                    if (String.IsNullOrEmpty(dd) == true) { error = "dd不能为空"; return false; }
                    else
                    {
                        if (dd.Length != 2)
                        {
                            error = "dd长度错误";
                            return false;
                        }
                        if (dd.Contains("_"))
                        {
                            error = "dd包含_字符";
                            return false;
                        }
                        try
                        {
                            int i = int.Parse(dd);
                            if ((i < 1) || (i > 31))
                            {
                                error = "dd值超出范围";
                                return false;
                            }
                        }
                        catch (FormatException)
                        {
                            error = "dd格式错误";
                            return false;
                        }
                    }
                    #endregion

                    #region PIC1 must 图片1路径,如http://172.16.22.2/卡口/某某路口/2014/05/09/6511-20140505101010-555-3-1.jpg
                    if (String.IsNullOrEmpty(PIC1) == true) { error = "PIC1不能为空"; return false; }
                    else
                    {
                        if (PIC1.Contains("_"))
                        {
                            error = "PIC1包含_字符";
                            return false;
                        }
                        if (!PIC1.ToLower().EndsWith(".jpg"))
                        {
                            error = "PIC1扩展名错误";
                            return false;
                        }

                        if (PIC1.Contains(":") || PIC1.Contains("/") || PIC1.Contains("\\"))
                        {
                            error = "上传图片数据时,PIC1为不含路径图片名";
                            return false;
                        }

                    }
                    #endregion

                    #region PIC2 not must 图片2路径,如http://172.16.22.2/卡口/某某路口/2014/05/09/6511-20140505101010-555-3-2.jpg
                    if (PIC2 == null) { error = "PIC2不能为null"; return false; }
                    else
                    {
                        if (PIC2 != "")
                        {
                            if (PIC2.Contains("_"))
                            {
                                error = "PIC2包含_字符";
                                return false;
                            }
                            if (!PIC2.ToLower().EndsWith(".jpg"))
                            {
                                error = "PIC2扩展名错误";
                                return false;
                            }

                            if (PIC2.Contains(":") || PIC2.Contains("/") || PIC2.Contains("\\"))
                            {
                                error = "上传图片数据时,PIC2为不含路径图片名";
                                return false;
                            }

                        }
                    }
                    #endregion

                    #region 图片3路径,如http://172.16.22.2/卡口/某某路口/2014/05/09/6511-20140505101010-555-3-3.jpg
                    if (PIC3 == null) { error = "PIC3不能为null"; return false; }
                    else
                    {
                        if (PIC3 != "")
                        {
                            if (PIC3.Contains("_"))
                            {
                                error = "PIC3包含_字符";
                                return false;
                            }
                            if (!PIC3.ToLower().EndsWith(".jpg"))
                            {
                                error = "PIC3扩展名错误";
                                return false;
                            }

                            if (PIC3.Contains(":") || PIC3.Contains("/") || PIC3.Contains("\\"))
                            {
                                error = "上传图片数据时,PIC3为不含路径图片名";
                                return false;
                            }

                        }
                    }
                    #endregion

                    #region 图片4路径,备用
                    if (PIC4 == null) { error = "PIC4不能为null"; return false; }
                    else
                    {
                        if (PIC4 != "")
                        {
                            if (PIC4.Contains("_"))
                            {
                                error = "PIC4包含_字符";
                                return false;
                            }
                            if (!PIC4.ToLower().EndsWith(".jpg"))
                            {
                                error = "PIC4扩展名错误";
                                return false;
                            }

                            if (PIC4.Contains(":") || PIC4.Contains("/") || PIC4.Contains("\\"))
                            {
                                error = "上传图片数据时,PIC4为不含路径图片名";
                                return false;
                            }

                        }
                    }
                    #endregion

                    #region 压缩图片路径,如http://172.16.22.2/卡口/某某路口/2014/05/09/6511-20140505101010-555-1-1zoom.jpg
                    if (PICZoom == null) { error = "PICZoom不能为null"; return false; }
                    else
                    {
                        if (PICZoom != "")
                        {
                            if (PICZoom.Contains("_"))
                            {
                                error = "PICZoom包含_字符";
                                return false;
                            }
                            if (!PICZoom.ToLower().EndsWith(".jpg"))
                            {
                                error = "PICZoom扩展名错误";
                                return false;
                            }

                            if (PICZoom.Contains(":") || PICZoom.Contains("/") || PICZoom.Contains("\\"))
                            {
                                error = "上传图片数据时,PICZoom为不含路径图片名";
                                return false;
                            }

                        }
                    }
                    #endregion

                    #region 车牌图片路径,如http://172.16.22.2/卡口/某某路口/2014/05/09/6511-20140505101010-555-1-1plate.jpg
                    if (PICPlate == null) { error = "PICPlate不能为null"; return false; }
                    else
                    {
                        if (PICPlate != "")
                        {
                            if (PICPlate.Contains("_"))
                            {
                                error = "PICPlate包含_字符";
                                return false;
                            }
                            if (!PICPlate.ToLower().EndsWith(".jpg"))
                            {
                                error = "PICPlate扩展名错误";
                                return false;
                            }

                            if (PICPlate.Contains(":") || PICPlate.Contains("/") || PICPlate.Contains("\\"))
                            {
                                error = "上传图片数据时,PICPlate为不含路径图片名";
                                return false;
                            }

                        }
                    }
                    #endregion

                    #region PIC1Bytes

                    if (PIC1Bytes == null)
                    {
                        error = "PIC1Bytes为null";
                        return false;
                    }
                    else
                    {
                        if (PIC1Bytes.Length < 10)
                        {
                            error = "PIC1Bytes<10";
                            return false;
                        }
                    }

                    #endregion
                    #endregion
                }
                catch (Exception er)
                {
                    error = "参数校验出现异常" + er.Message;
                    return false;
                }

                string path = "";
                string path1 = "";
                string path2 = "";
                string path3 = "";
                string path4 = "";
                string path5 = "";
                string path6 = "";

                if (recordType == "0")//卡口
                {
                    path = gKKIISPath + "\\" + roadname + "\\" + yyyy + "\\" + MM + "\\" + dd;
                }
                else
                {
                    path = gDJIISPath + "\\" + yyyy + MM + dd + "\\" + roadname;//睢宁保存路径
                }
                if (!Directory.Exists(path)) Directory.CreateDirectory(path);
                path1 = ((PIC1 == "") ? "" : (path + "\\" + PIC1));
                path2 = ((PIC2 == "") ? "" : (path + "\\" + PIC2));
                path3 = ((PIC3 == "") ? "" : (path + "\\" + PIC3));
                path4 = ((PIC4 == "") ? "" : (path + "\\" + PIC4));
                path5 = ((PICZoom == "") ? "" : (path + "\\" + PICZoom));
                path6 = ((PICPlate == "") ? "" : (path + "\\" + PICPlate));


                if (PIC1Bytes != null) File.WriteAllBytes(path1, PIC1Bytes);
                if (PIC2Bytes != null) File.WriteAllBytes(path2, PIC2Bytes);
                if (PIC3Bytes != null) File.WriteAllBytes(path3, PIC3Bytes);
                if (PIC4Bytes != null) File.WriteAllBytes(path4, PIC4Bytes);
                if (PICZoomBytes != null) File.WriteAllBytes(path5, PICZoomBytes);
                if (PICPlateBytes != null) File.WriteAllBytes(path6, PICPlateBytes);
                ans = true;
            }
            catch (Exception er)
            {
                ans = false;
                error = "UploadPicOnly()异常" + er.Message;
            }
            return ans;
        }

        /// <summary>
        /// 检查版本更新
        /// </summary>
        /// <param name="c_version">client版本号</param>
        /// <param name="s_version">server版本号</param>
        /// <param name="exe">可执行程序</param>
        /// <returns>true-有新版本false-没有</returns>
        [WebMethod]
        public bool JKZP_HasNewVersion(string c_version,out string s_version ,out byte[] exe)
        {
            bool ans = false;
            exe = null;
            s_version = gVersion;
            try
            {
                if ((c_version != null) && (c_version != ""))
                {
                    if (gVersion != c_version)
                    { 
                        string exePath = HttpContext.Current.Request.MapPath("~/App_Data/JKZPXML/JKZP.exe");
                        exe = File.ReadAllBytes(exePath);
                        ans = true;
                    }
                }
            }
            catch { exe = null; }
            return ans;
        }

        /// <summary>
        /// JKZP_DPSDKGetWFDDDM
        /// </summary>
        /// <param name="dpsdkwfdd">dpsdkwfdd</param>
        /// <param name="error">error</param>
        /// <returns>jieguo</returns>
        [WebMethod]
        public bool JKZP_DPSDKGetWFDDDM(out string dpsdkwfdd,out string error)
        {
            bool ans = false;
            error = "";
            dpsdkwfdd = "";
            try
            {
                string wfddfile = HttpContext.Current.Request.MapPath("~/App_Data/JKZPXML/dpsdkwfdd.xml");
                if (File.Exists(wfddfile))
                {
                    dpsdkwfdd = File.ReadAllText(wfddfile);
                    ans = true;
                }
            }
            catch (Exception er)
            {
                ans = false;
                error = "JKZP_DPSDKGetWFDDDM()异常" + er.Message;
            }
            return ans;
        }

        /// <summary>
        /// JKZP注册
        /// </summary>
        /// <param name="username">用户名</param>
        /// <param name="password">密码</param>
        /// <param name="admin">是否管理员</param>
        /// <param name="xml">参数</param>
        /// <param name="road">路口</param>
        /// <param name="wfxwdm">违法行为代码</param>
        /// <param name="hpzl">号牌种类</param>
        /// <param name="error">错误信息</param>
        /// <returns>登录结果</returns>
        [WebMethod]
        public bool JKZP_Login(string username, string password, out bool admin,out string xml,out string road,out string wfxwdm,out string hpzl, out string error)
        { 
            bool ans = false;
            error="";
            admin = false;
            xml = "";
            road = "";
            wfxwdm = "";
            hpzl = "";

            try
            {
                string userPath = HttpContext.Current.Request.MapPath("~/App_Data/JKZPXML/user.xml");
                string wfxwdmPath = HttpContext.Current.Request.MapPath("~/App_Data/JKZPXML/WFXWDM.txt");
                string hpzlPath = HttpContext.Current.Request.MapPath("~/App_Data/JKZPXML/HPZL.txt");
                string paramfile = HttpContext.Current.Request.MapPath("~/App_Data/JKZPXML/param.xml");
                string roadfile = HttpContext.Current.Request.MapPath("~/App_Data/JKZPXML/road.xml");
                
                if (File.Exists(userPath))
                {
                    XmlDocument doc = new XmlDocument();
                    doc.Load(userPath);
                    XmlNode node = doc.SelectSingleNode("param/user[@username='" + username + "' and @password='" + password + "']");
                    if (node != null)
                    {
                        admin = bool.Parse(node.Attributes["admin"].Value);
                        wfxwdm = File.ReadAllText(wfxwdmPath);
                        hpzl = File.ReadAllText(hpzlPath);
                        xml = File.ReadAllText(paramfile);
                        road = File.ReadAllText(roadfile);

                        ans = true;
                    }
                    
                }
            }
            catch (Exception er)
            {
                ans = false;
                error = "JKZP_Login()异常" + er.Message;
            }
            return ans;
        }

        /// <summary>
        /// 上传WFXWDM
        /// </summary>
        /// <param name="xml">xml内容</param>
        /// <returns>结果</returns>
        [WebMethod]
        public bool JKZP_UploadWFXWDM(string xml)
        {
            bool ans = false;
            try
            {
                if (xml != "")
                {
                    string path = HttpContext.Current.Request.MapPath("~/App_Data/JKZPXML/WFXWDM.txt");
                    File.WriteAllText(path,xml);
                    ans = true;
                }
            }
            catch { ans = false; }
            return ans;
        }

        /// <summary>
        /// 上传HPZL
        /// </summary>
        /// <param name="xml">xml内容</param>
        /// <returns>结果</returns>
        [WebMethod]
        public bool JKZP_UploadHPZL(string xml)
        {
            bool ans = false;
            try
            {
                if (xml != "")
                {
                    
                    string path = HttpContext.Current.Request.MapPath("~/App_Data/JKZPXML/HPZL.txt");


                    File.WriteAllText(path,xml);
                    ans = true;
                }
            }
            catch { ans = false; }
            return ans;
        }

        /// <summary>
        /// 上传Param
        /// </summary>
        /// <param name="xml">xml内容</param>
        /// <returns>结果</returns>
        [WebMethod]
        public bool JKZP_UploadParam(string xml)
        {
            bool ans = false;
            try
            {
                if (xml != "")
                {

                    string path = HttpContext.Current.Request.MapPath("~/App_Data/JKZPXML/param.xml");

                    File.WriteAllText(path,xml);
                    ans = true;
                }
            }
            catch { ans = false; }
            return ans;
        }

        /// <summary>
        /// 上传Road
        /// </summary>
        /// <param name="xml">xml内容</param>
        /// <returns>结果</returns>
        [WebMethod]
        public bool JKZP_UploadRoad(string xml)
        {
            bool ans = false;
            try
            {
                if (xml != "")
                {
                    string path = HttpContext.Current.Request.MapPath("~/App_Data/JKZPXML/road.xml");

                    File.WriteAllText(path,xml);
                    ans = true;
                }
            }
            catch { ans = false; }
            return ans;
        }
        /// <summary>
        /// 用户清单
        /// </summary>
        /// <returns>用户清单</returns>
        [WebMethod]
        public string JKZP_UserList()
        {
            string ans = "";
            try
            {
                string userPath = HttpContext.Current.Request.MapPath("~/App_Data/JKZPXML/user.xml");
                if (File.Exists(userPath))
                {
                    ans = File.ReadAllText(userPath);
                }
            }
            catch 
            {
                ans = "";
            }
            return ans;
        }

        /// <summary>
        /// 修改密码
        /// </summary>
        /// <param name="username">用户名</param>
        /// <param name="oldpassword">旧密码</param>
        /// <param name="newpassword">新密码</param>
        /// <returns>结果</returns>
        [WebMethod]
        public bool JKZP_ChangePassword(string username, string oldpassword, string newpassword)
        {
            bool ans = false;
            try
            {
                string userPath = HttpContext.Current.Request.MapPath("~/App_Data/JKZPXML/user.xml");
                if (File.Exists(userPath))
                {
                    XmlDocument doc = new XmlDocument();
                    doc.Load(userPath);
                    XmlNode node = doc.SelectSingleNode("param/user[@username='" + username + "' and @password='" + oldpassword + "']");
                    if (node != null)
                    {
                        node.Attributes["password"].Value = newpassword;
                        doc.Save(userPath);
                        ans = true;
                    }

                }
            }
            catch { ans = false; }
            return ans;
        }

        /// <summary>
        /// 读取路段参数
        /// </summary>
        /// <returns>结果</returns>
        [WebMethod]
        public string JKZP_GetLuDuan()
        {
            string ans = "";
            try
            {
                string ldPath = HttpContext.Current.Request.MapPath("~/App_Data/JKZPXML/luduan.xml");
                if (File.Exists(ldPath))
                {
                    ans = File.ReadAllText(ldPath);
                }
            }
            catch
            {
                ans = "";
            }
            return ans;
        }

        /// <summary>
        /// 添加路段
        /// </summary>
        /// <param name="ld">路段名称</param>
        /// <returns>结果</returns>
        [WebMethod]
        public bool JKZP_AddLuDuan(string ld)
        {
            bool ans = false;
            try
            {
                string wfddpath = HttpContext.Current.Request.MapPath("~/App_Data/JKZPXML/luduan.xml");
                if (File.Exists(wfddpath))
                {
                    ans = AddConfig(wfddpath, "descendant::param", "luduan", ld, null, null);
                }
            }
            catch { ans = false; }
            return ans;
        }

        /// <summary>
        /// 路口关联路段
        /// </summary>
        /// <param name="roadid">路口</param>
        /// <param name="luduan">路段</param>
        /// <returns>结果</returns>
        [WebMethod]
        public bool JKZP_SetLuDuan(string roadid, string luduan)
        {
            bool ans = false;
            try
            {
                string userPath = HttpContext.Current.Request.MapPath("~/App_Data/JKZPXML/road.xml");
                XmlDocument doc = new XmlDocument();
                if (File.Exists(userPath))
                {
                    doc.Load(userPath);
                    XmlNode node = doc.SelectSingleNode("descendant::road[@roadid='" + roadid + "']");
                    if (node != null)
                    {
                        node.Attributes["luduan"].Value = luduan;
                        doc.Save(userPath);
                        ans = true;
                    }
                }
            }
            catch { ans = false; }
            return ans;
        }

        /// <summary>
        /// 删除路段
        /// </summary>
        /// <param name="ld">路段名称</param>
        /// <returns>结果</returns>
        [WebMethod]
        public bool JKZP_DelLuDuan(string ld)
        {
            bool ans = false;
            try
            {
                string userPath = HttpContext.Current.Request.MapPath("~/App_Data/JKZPXML/luduan.xml");
                XmlDocument doc = new XmlDocument();
                if (File.Exists(userPath))
                {
                    doc.Load(userPath);
                    XmlNodeList nodes = doc.SelectNodes("param/luduan");

                    foreach (XmlNode node in nodes)
                    {
                        if (node.InnerText == ld)
                        {
                            node.ParentNode.RemoveChild(node);
                            doc.Save(userPath);
                            ans = true;
                            break;
                        }
                    }
                }
            }
            catch { ans = false; }
            return ans;
        }

        /// <summary>
        /// 添加标志图
        /// </summary>
        /// <param name="filename">文件名</param>
        /// <param name="picbytes">文件</param>
        /// <returns>结果</returns>
        [WebMethod]
        public bool JKZP_AddBZT(string filename,byte[] picbytes)
        {
            bool ans = false;
            try
            {
                string wfddpath = HttpContext.Current.Request.MapPath("~/App_Data/JKZPXML/biaozhitu/" + filename);
                if ((picbytes != null) && (picbytes.Length > 0))
                {
                    File.WriteAllBytes(wfddpath, picbytes);
                    ans = true;
                }
            }
            catch { ans = false; }
            return ans;
        }

        /// <summary>
        /// 获取标志图
        /// </summary>
        /// <param name="filename">文件名</param>
        /// <param name="picbytes">数据</param>
        /// <returns>结果</returns>
        [WebMethod]
        public bool JKZP_GetBZT(string filename,out byte[] picbytes)
        {
            bool ans = false;
            picbytes = null;
            try
            {
                string wfddpath = HttpContext.Current.Request.MapPath("~/App_Data/JKZPXML/biaozhitu/" + filename);
                if (File.Exists(wfddpath))
                {
                    picbytes = File.ReadAllBytes(wfddpath);
                    ans = true;
                }
            }
            catch { ans = false; }
            return ans;
        }

        /// <summary>
        /// 添加或编辑DPSDK的地点代码
        /// </summary>
        /// <param name="camid">摄像机编号</param>
        /// <param name="wfdddm">地点代码</param>
        /// <returns>结果</returns>
        [WebMethod]
        public bool JKZP_AddOrEditDPSDKWFDD(string camid, string wfdddm)
        {
            bool ans = false;
            try
            {
                string wfddpath = HttpContext.Current.Request.MapPath("~/App_Data/JKZPXML/dpsdkwfdd.xml");
                if (File.Exists(wfddpath))
                {
                    XmlDocument doc = new XmlDocument();
                    doc.Load(wfddpath);
                    XmlNode node = doc.SelectSingleNode("param/wfdd[@camid='" + camid + "']");
                    if (node != null)
                    {
                        node.Attributes["wfdddm"].Value = wfdddm;
                        doc.Save(wfddpath);
                        ans = true;
                    }
                    else
                    {
                        string[] key = new string[2];
                        string[] value = new string[2];
                        key[0] = "camid";
                        key[1] = "wfdddm";

                        value[0] = camid;
                        value[1] = wfdddm;

                        ans = AddConfig(wfddpath, "descendant::param", "wfdd", "", key, value);
                    }
                }
            }
            catch { ans = false; }
            return ans;
        }

        /// <summary>
        /// 添加用户
        /// </summary>
        /// <param name="username">用户名</param>
        /// <param name="password">密码</param>
        /// <param name="admin">管理员权限</param>
        /// <param name="roadids">点位分配</param>
        /// <returns>结果</returns>
        [WebMethod]
        public bool JKZP_AddUser(string username, string password, string admin, string roadids)
        {
            bool ans = false;
            bool ans1 = false;
            bool ans2 = false;
            try
            {


                string userPath = HttpContext.Current.Request.MapPath("~/App_Data/JKZPXML/user.xml");
                if (File.Exists(userPath))
                {
                    string[] key = new string[3];
                    string[] value = new string[3];
                    key[0] = "username";
                    key[1] = "password";
                    key[2] = "admin";
                    value[0] = username;
                    value[1] = password;
                    value[2] = admin;
                    ans1 = AddConfig(userPath, "descendant::param", "user", "", key, value);
                }

                string roadfile = HttpContext.Current.Request.MapPath("~/App_Data/JKZPXML/road.xml");
                if (roadids != "")
                {
                    XmlDocument doc = new XmlDocument();
                    doc.Load(roadfile);
                    XmlNodeList nodes = doc.SelectNodes("descendant::road");
                    if (nodes != null)
                    {
                        foreach (XmlNode node in nodes)
                        {
                            if (roadids.Contains(node.Attributes["roadid"].Value + "-"))
                            {
                                if (!node.Attributes["user"].Value.Contains(username + "-"))
                                {
                                    node.Attributes["user"].Value = (node.Attributes["user"].Value + username + "-");
                                }
                            }
                            else
                            {
                                if (node.Attributes["user"].Value.Contains(username + "-"))
                                {
                                    node.Attributes["user"].Value = (node.Attributes["user"].Value.Replace(username + "-", ""));
                                }
                            }

                            //XmlNode father = node.ParentNode;
                            //XmlNode newnode = node.CloneNode(true);

                            //if (roadids.Contains(newnode.Attributes["roadid"].Value + "-"))
                            //{
                            //    if (!newnode.Attributes["user"].Value.Contains(username + "-"))
                            //    {
                            //        newnode.Attributes["user"].Value = (newnode.Attributes["user"].Value + username + "-");
                            //    }
                            //}
                            //else
                            //{
                            //    if (newnode.Attributes["user"].Value.Contains(username + "-"))
                            //    {
                            //        newnode.Attributes["user"].Value = (newnode.Attributes["user"].Value.Replace(username + "-", ""));
                            //    }
                            //}
                            //if (node.HasChildNodes)
                            //{
                            //    foreach (XmlNode child in node.ChildNodes)
                            //    {
                            //        newnode.AppendChild(child.CloneNode(true));
                            //    }
                            //}
                            //father.ReplaceChild(newnode, node);
                        }
                        doc.Save(roadfile);
                        ans2 = true;
                    }
                    
                }
                else
                {
                    ans2=true;
                }

                ans = (ans1 && ans2);
                
            }
            catch { ans = false; }
            return ans;
        }

        /// <summary>
        /// 修改用户
        /// </summary>
        /// <param name="username">用户名</param>
        /// <param name="admin">管理员权限</param>
        /// <param name="roadids">点位分配</param>
        /// <returns>结果</returns>
        [WebMethod]
        public bool JKZP_EditUser(string username, string admin, string roadids)
        {
            bool ans = false;
            bool ans1 = false;
            bool ans2 = false;
            try
            {
                string userPath = HttpContext.Current.Request.MapPath("~/App_Data/JKZPXML/user.xml");
                XmlDocument doc = new XmlDocument();
                if (File.Exists(userPath))
                {
                    doc.Load(userPath);
                    XmlNode node = doc.SelectSingleNode("param/user[@username='" + username + "']");
                    if (node != null)
                    {
                        node.Attributes["admin"].Value = admin;
                        doc.Save(userPath);
                        ans1 = true;
                    }
                    
                }

                string roadfile = HttpContext.Current.Request.MapPath("~/App_Data/JKZPXML/road.xml");
                if (roadids != "")
                {
                    doc.RemoveAll();
                    doc.Load(roadfile);
                    XmlNodeList nodes = doc.SelectNodes("descendant::road");
                    if (nodes != null)
                    {
                        foreach (XmlNode node in nodes)
                        {
                            if (roadids.Contains(node.Attributes["roadid"].Value + "-"))
                            {
                                if (!node.Attributes["user"].Value.Contains(username + "-"))
                                {
                                    node.Attributes["user"].Value = (node.Attributes["user"].Value + username + "-");
                                }
                            }
                            else
                            {
                                if (node.Attributes["user"].Value.Contains(username + "-"))
                                {
                                    node.Attributes["user"].Value = (node.Attributes["user"].Value.Replace(username + "-", ""));
                                }
                            }

                            //XmlNode father = node.ParentNode;
                            //XmlNode newnode = node.CloneNode(true);

                            //if (roadids.Contains(newnode.Attributes["roadid"].Value + "-"))
                            //{
                            //    if (!newnode.Attributes["user"].Value.Contains(username + "-"))
                            //    {
                            //        newnode.Attributes["user"].Value = (newnode.Attributes["user"].Value + username + "-");
                            //    }
                            //}
                            //else
                            //{
                            //    if (newnode.Attributes["user"].Value.Contains(username + "-"))
                            //    {
                            //        newnode.Attributes["user"].Value = (newnode.Attributes["user"].Value.Replace(username + "-", ""));
                            //    }
                            //}
                            //if (node.HasChildNodes)
                            //{
                            //    foreach (XmlNode child in node.ChildNodes)
                            //    {
                            //        newnode.AppendChild(child.CloneNode(true));
                            //    }
                            //}
                            //father.ReplaceChild(newnode, node);
                        }
                        doc.Save(roadfile);
                        ans2 = true;
                    }

                }
                else
                {
                    ans2 = true;
                }

                ans = (ans1 && ans2);

            }
            catch { ans = false; }
            return ans;
        }

        /// <summary>
        /// 删除用户
        /// </summary>
        /// <param name="username">用户名</param>
        /// <returns>结果</returns>
        [WebMethod]
        public bool JKZP_DeleteUser(string username)
        {
            bool ans = false;
            bool ans1 = false;
            bool ans2 = false;
            try
            {
                string userPath = HttpContext.Current.Request.MapPath("~/App_Data/JKZPXML/user.xml");
                XmlDocument doc = new XmlDocument();
                if (File.Exists(userPath))
                {
                    doc.Load(userPath);
                    XmlNode node = doc.SelectSingleNode("param/user[@username='" + username + "']");
                    if (node != null)
                    {
                        node.RemoveAll();
                        node.ParentNode.RemoveChild(node);
                        doc.Save(userPath);
                        ans1 = true;
                    }
                }

                string roadfile = HttpContext.Current.Request.MapPath("~/App_Data/JKZPXML/road.xml");
                if (File.Exists(roadfile))
                {
                    doc.RemoveAll();
                    doc.Load(roadfile);
                    XmlNodeList nodes = doc.SelectNodes("descendant::road");
                    if (nodes != null)
                    {
                        foreach (XmlNode node in nodes)
                        {
                            if (node.Attributes["user"].Value.Contains(username + "-"))
                            {
                                node.Attributes["user"].Value = (node.Attributes["user"].Value.Replace(username + "-", ""));
                            }
                        }
                        doc.Save(roadfile);
                        ans2 = true;
                    }
                }
                
                ans = (ans1 && ans2);
            }
            catch { ans = false; }
            return ans;
        }

        /// <summary>
        /// 上传工作量
        /// </summary>
        /// <param name="username">用户名</param>
        /// <param name="n">工作量</param>
        /// <returns>结果</returns>
        [WebMethod]
        public bool JKZP_UploadGZL(string username, int n)
        {
            bool ans = false;
            try
            {
                string head = DateTime.Now.ToString("yyyyMM");
                int dd = DateTime.Now.Day;

                if ((username != "") && (n > 0))
                {
                    string filename = HttpContext.Current.Request.MapPath("~/App_Data/JKZPXML/" + username + ".txt");
                    if (File.Exists(filename))
                    {
                        bool found = false;
                        string[] lines = File.ReadAllLines(filename);
                        if((lines!=null)&&(lines.Length>0))
                        {
                            for (int j = 0; j < lines.Length;j++ )
                            {
                                if (lines[j].StartsWith(head))
                                {
                                    found = true;
                                    string[] ss = lines[j].Split('-');
                                    if ((ss != null) && (ss.Length == 32))
                                    {
                                        int old = int.Parse(ss[dd]);
                                        int total = old + n;
                                        ss[dd] = total.ToString();
                                        string temp = head;
                                        for (int i = 1; i < ss.Length; i++)
                                        {
                                            temp += ("-" + ss[i]);
                                        }
                                        lines[j] = temp;
                                    }
                                    File.WriteAllLines(filename, lines);
                                    ans = true;
                                    break;
                                }
                            }

                            if (found == false)
                            {
                                string temp = head;
                                for (int i = 1; i < 32; i++)
                                {
                                    if (i == dd)
                                    {
                                        temp += ("-" + n.ToString());
                                    }
                                    else
                                    {
                                        temp += ("-0");
                                    }
                                }
                                string line = temp + "\r\n";
                                File.AppendAllText(filename, line);
                                ans = true;
                            }
                        }
                    }
                    else
                    {
                        string temp = head;
                        for (int i = 1; i < 32; i++)
                        {
                            if (i == dd)
                            {
                                temp += ("-" + n.ToString());
                            }
                            else
                            {
                                temp += ("-0");
                            }
                        }
                        string line = temp + "\r\n";
                        File.WriteAllText(filename, line);
                        ans = true;
                    }
                }
            }
            catch { ans = false; }
            return ans;
        }

        /// <summary>
        /// 查询工作量
        /// </summary>
        /// <param name="username">用户名</param>
        /// <param name="from">开始时间</param>
        /// <param name="to">结束时间</param>
        /// <returns>结果</returns>
        [WebMethod]
        public int JKZP_GetGZL(string username, string from, string to)
        {
            int ans = 0;
            try
            {
                if ((username != "") && (from != "") && (to != ""))
                {
                    string filename = HttpContext.Current.Request.MapPath("~/App_Data/JKZPXML/" + username + ".txt");
                    DateTime t1 = DateTime.Parse(from);
                    DateTime t2 = DateTime.Parse(to);

                    if (File.Exists(filename))
                    {
                        string[] lines = File.ReadAllLines(filename);
                        if ((lines != null) && (lines.Length > 0))
                        {
                            foreach (string line in lines)
                            {
                                if (line != "")
                                {
                                    int yyyy = int.Parse(line.Substring(0, 4));
                                    int MM = int.Parse(line.Substring(4, 2));
                                    string[] ss = line.Split('-');
                                    if ((ss != null) && (ss.Length == 32))
                                    {
                                        for (int i = 1; i < ss.Length; i++)
                                        {
                                            if (ss[i] != "0")
                                            {
                                                DateTime t = new DateTime(yyyy, MM, i);
                                                if ((t1 <= t) && (t <= t2))
                                                {
                                                    ans += (int.Parse(ss[i]));
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
            catch { ans = 0; }
            return ans;
        }

        /// <summary>
        /// 修改预置点
        /// </summary>
        /// <param name="ip">球机ip</param>
        /// <param name="index">预置点编号从0开始</param>
        /// <param name="yzdname">预置点名称</param>
        /// <returns>结果</returns>
        [WebMethod]
        public bool JKZP_EditYZD(string ip, string index,string yzdname)
        {
            bool ans = false;
            try
            {
                if ((ip != "") && (index != "") && (yzdname != ""))
                {
                    string roadfile = HttpContext.Current.Request.MapPath("~/App_Data/JKZPXML/road.xml");
                    if (File.Exists(roadfile))
                    {
                        XmlDocument doc = new XmlDocument();
                        doc.RemoveAll();
                        doc.Load(roadfile);
                        string xpath = "descendant::camera[@ip='" + ip + "']/PreSetPoint[@index='" + index + "']";
                        XmlNode node = doc.SelectSingleNode(xpath);

                        if (node != null)
                        {
                            node.InnerText = yzdname;
                            doc.Save(roadfile);
                            ans = true;
                        }
                    }
                }
            }
            catch { ans = false; }
            return ans;
        }


        private bool AddConfig(string xmlFilePath, string fatherNodeXPath, string nodename, string innerText, string[] attributeName, string[] attributeValue)
        {
            bool ans = false;
            XmlDocument doc = new XmlDocument();
            try
            {
                doc.Load(xmlFilePath);
                XmlNode fathernode = doc.SelectSingleNode(fatherNodeXPath);
                if (fathernode != null)
                {
                    XmlElement childnode = doc.CreateElement(nodename);
                    childnode.InnerText = innerText;
                    if (attributeName != null)
                    {
                        for (int i = 0; i < attributeName.Length; i++)
                        {
                            childnode.SetAttribute(attributeName[i], attributeValue[i]);
                        }
                    }
                    fathernode.AppendChild(childnode);
                    doc.Save(xmlFilePath);
                    ans = true;
                }
            }
            catch
            {
                ans = false;
            }
            return ans;

        }

        private bool SetConfig(string xmlFilePath, string nodeXPath, string innerText, string[] attributeName, string[] attributeValue)
        {
            bool ans = false;
            XmlDocument doc = new XmlDocument();
            try
            {
                doc.Load(xmlFilePath);
                XmlNode node = doc.SelectSingleNode(nodeXPath);

                if (node != null)
                {
                    //路口保存时需要保留原有的下属摄像机参数
                    //修改摄像机参数时要保存预置点参数
                    if (nodeXPath.Contains("road") || nodeXPath.Contains("camera"))
                    {
                        XmlNode father = node.ParentNode;
                        XmlNode newnode = node.CloneNode(true);
                        newnode.InnerText = innerText;
                        if (attributeName != null)
                        {
                            for (int i = 0; i < attributeName.Length; i++)
                            {
                                newnode.Attributes[attributeName[i]].Value = attributeValue[i];
                            }
                        }
                        if (node.HasChildNodes)
                        {
                            foreach (XmlNode child in node.ChildNodes)
                            {
                                newnode.AppendChild(child.CloneNode(true));
                            }
                        }
                        //father.AppendChild(newnode);
                        father.ReplaceChild(newnode, node);
                        doc.Save(xmlFilePath);
                        ans = true;
                    }
                    else
                    {
                        node.InnerText = innerText;
                        if (attributeName != null)
                        {
                            for (int i = 0; i < attributeName.Length; i++)
                            {
                                node.Attributes[attributeName[i]].Value = attributeValue[i];
                            }
                        }
                        doc.Save(xmlFilePath);
                        ans = true;
                    }
                }

            }
            catch
            {
                ans = false;
            }
            return ans;

        }

        private bool DelConfig(string xmlFilePath, string nodeXPath, bool keepSelf)
        {
            bool ans = false;
            XmlDocument doc = new XmlDocument();
            try
            {
                if (File.Exists(xmlFilePath))
                {
                    doc.Load(xmlFilePath);
                    XmlNode node = doc.SelectSingleNode(nodeXPath);
                    if (node != null)
                    {
                        node.RemoveAll();
                        if (!keepSelf)
                        {
                            node.ParentNode.RemoveChild(node);
                        }
                        doc.Save(xmlFilePath);
                        ans = true;
                    }
                }
            }
            catch
            {
                ans = false;
            }
            return ans;

        }
        
    }
}
